import writeXlsxFile from 'write-excel-file';

var filefy = require("filefy");

/* col: ["a", "b", "c"]
 * row: [["a2", "b1", "c1"]]
*/
const export_csv_file = (fileName, col, row) => {
    let builder = new filefy.CsvBuilder(fileName + ".csv");

    builder.setDelimeter(",").setColumns(col).addRows(row).exportFile();
};

/* [
 *   [{value: "x"}, {value: "x2"}]
 * ]
*/
const save_xlsx = (row, name, hcmd) => {
    writeXlsxFile(row, {fileName: name})
        .then(v => {
            if (hcmd) {
                hcmd();
            }
        });
};

export {save_xlsx, export_csv_file};
